home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-03-19 | 38.0 KB | 1,006 lines | [TEXT/MPS ] |
- #
- # ****************************************************************************
- #
- # File Name: StandardFile.Lib
- #
- # Contains: Tasks that support Standard File operations.
- #
- # Written by: KTA, KL, ML, GS et al
- #
- # Copyright: © 1993-1996 by Apple Computer, Inc., all rights reserved.
- #
- # ****************************************************************************
- # C h a n g e H i s t o r y (most recent first):
- # ****************************************************************************
- #
- # Vers Date Author Description
- # ---- -------- ------ ---------------------------------------------
- # <1.1.18> 5/1/96 MDF Revert() - handles button selection for Intl case
- # correctly. OpenFile() - removed feature for handling
- # MacEasy Open in since no longer applicable.
- # 1.1.17+> 5/1/96 MDF Revert() - handles button selection for Intl case correctly.
- # OpenFile() - removed feature for handling MacEasy Open in since
- # no longer applicable.
- # <1.1.17> 11/21/95 ML SaveAs - revise for dirty quit. Revert - add support for
- # international
- # 1.1.16+> 11/20/95 ML SaveAs - revise for dirty quit
- # <1.1.16> 4/11/95 KTA Syntax Error : Forgot ')'
- # <1.1.15> 4/11/95 KTA SaveAs(), OpenFile() - Insure global gIsSys7 is defined.
- # <1.1.14> 2/28/95 KTA SaveAs(), ReplaceExist() - Added calls to TruncateString().
- # <1.1.13> 2/28/95 KTA SaveAs(), ReplaceExist() - Handle filenames longer than 31
- # characters
- # <1.1.12> 2/14/95 KTA SaveAs() - Call _MatchBoolean before trying to collect buttons
- # on 'Replace Existing' Dialog to avoid calling the
- # DefaultHandler.
- # <1.1.11> 2/14/95 KTA SaveAs(), OpenDoc() - Added BooleanFlag to FindWindow() call
- # <1.1.10> 2/10/95 ML IsStandardFile, CancelStandardFile - Use MatchBoolean instead of
- # Match
- # <1.1.9> 1/19/95 KTA Changed the name of ExceptionHandler() to ExceptionDispatcher().
- # <1.1.8> 1/9/95 KTA SFNavigate(), SFType() - Fixed bug when StandardFile was already
- # at the Desktop errors occured
- # <1.1.7> 12/13/94 ML Revise IsSys7 to gIsSys7, change IsSys7 to gIsSys7
- # <1.1.6> 12/1/94 ML Revise Revert()
- # <1.1.5> 11/30/94 ML Added exception handling support
- # <1.1.4> 7/18/94 KTA SFNavigate() - Added a check to insure that PathList is defined.
- # <1.1.3> 5/9/94 KTA SaveAs() - If not IsStandardFile() wait and try to match again.
- # <1.1.2> 5/3/94 ML Revise Easy open dialog check
- # <1.1.1> 5/2/94 ML Better check for Mac Easy Open Dialog
- # <1.1.0> 4/28/94 KTA SaveAs() - If unable to match 'Replace Existing dialog' try again.
- # 1.0.211> 4/20/94 ML Add Mac Easy Open Dialog Check to OpenFile
- # 1.0.210> 4/20/94 ML marked tasks
- # <1.0.29> 4/7/94 ML Add global gReplaceExistHook1 and gReplaceExistHook2
- # <1.0.28> 1/7/94 RTV OpenFile was passing a list to TCSEnd instead of a string for the doc name
- # <1.0.27> 12/16/93 KTA ModifyDocument was not returning correct values.
- # <1.0.26> 12/14/93 KTA Changed the way ModifyDocuemtn handles return values.
- # <1.0.25> 12/13/93 KTA OpenFile returns the name of the file it opened.
- # <1.0.24> 11/19/93 NAGA modify TCS format
- # <1.0.23> 10/05/93 KTA Revert() - Added longer wait before trying to dismiss dialog and
- # support for hierachical menus
- # <1.0.22> 10/05/93 KTA ModifyDocument() - Change returnVal to a 1 if it was successful.
- # <1.0.21> 9/30/93 KTA SaveAs() - Updated the output after saving a document.
- # <1.0.20> 9/28/93 KTA ModifyDocument() - Added TCS - 'Modify a Document'
- # <1.0.19> 9/28/93 KTA ModifyDocument() - Handle problem caused if gModifyDocument hook doesn't return a value
- # <1.0.18> 9/22/93 KTA Renamed gSaveOtherFormat -> SaveAsHook1, gEndTimer -> SaveAsHook2
- # gDismissSFPut -> gSaveAsHook3,gOpenFileHook -> gOpenFileHook1,
- # gEndTimer ->gOpenFileHook2, Removed pParameter1 from OpenFile()
- # <1.0.17> 9/14/93 KTA SaveAs() - gCustomRetrievedDoc wasn't being used
- # because it was not defined as global.
- # <1.0.16> 9/9/93 KTA Removed all slang phrases from output.
- # <1.0.15> 8/30/93 KTA Updated task headers and parameters.
- # <1.0.14> 8/25/93 KTA Added support for parity checking the TCS stack.
- # <1.0.13> 7/30/93 KTA IsStandardFile - return window descriptor, ModifyDocument return
- # success/Failure. Openfile better check if standardfile gone.
- # <1.0.12> 7/23/93 KTA SaveAs() - moved gDismissSFPut to before we verify filename.
- # <1.0.11> 7/22/93 KTA Fixed bugs with file name verificaton, SaveAS(), OpenFile().
- # <1.0.10> 7/19/93 KTA FindWindow() now supports descriptors - updated references.
- # <1.0.9> 7/15/93 KTA Added undefined task reference - gReplaceExisting. Hook to
- # handle a custom "replace existing?" dialog. This was done for Lotus 123.
- # <1.0.8> 7/14/93 KTA International Support: See SaveAs(), OpenFile(),
- # CancelStandardFile(), Revert(), and Save().
- # <1.0.7> 7/6/93 KTA CustomRetrieveDoc change had a syntax error
- # <1.0.6> 7/6/93 KTA Performance Support
- # <1+> 5/21/93 NAGA Adding header and porting old files to follow new standards
- #
- # ****************************************************************************
- #
-
- ########################################################################
- # External libraries
- #=======================================================================
- Libraries "String.Lib","TCS.Lib","Output.Lib","UserInterface.Lib",
- "ExceptionHandling.lib", "TargetCheck.Lib";
-
- #########################################################################
- # SaveAs(pNameDoc, pReplaceFlag, pSelectSaveAs, pPathlist)
- #========================================================================
- # Author: KTA
- # Description: This routine will type a name (pNameDoc) into the text edit
- # field. Then it will press the ReturnKey to save the file.
- # If there is a document already named <pNameDoc> a dialog will
- # appear. If the <pReplaceFlag> evaluates to false
- # it will select NO to 'Replace Existing?' dialog. It will
- # then type the time (based on a 24 hour clock) after the
- # name and retype the ReturnKey. The Default is to replace
- # an existing document with the same name. It will also call
- # getNewFileName to create a file name if one is not provided.
- # Parameters: pNameDoc - string holding the name to name the document
- # pReplaceFlag - 0 to select 'No' to 'Replace Existing' dialog
- # 1 to select 'Yes' to replace exisiting file.
- # pSelectSaveAs - Flag which indicates whether or not to select
- # SaveAs menuItem.
- # 0 - Do not select SaveAs MenuItem
- # 1 - Select the SaveAs menuItem
- # {List} - Select the SaveAs menuItem using the
- # ord specified. e.g. {5,2}
- # pPathlist - Path to navigate before saving - should be complete path.
- # Returns: 0 - Unable to dismiss SFPut or never present to begin with
- # 1 - Dismissed SFPut ok, saved file, ReplaceExist not called
- # 2 - Dismissed SFPut ok, saved file, ReplaceExist called
- # Examples: SaveAs('Untitled1'); to name the file 'Untitled1'
- # Assumptions: That the SF_Put dialog is present
- #
- #========================================================================
- # History:
- # KTA 7/06/93 Performance Support: EndTimer
- # KTA 7/07/93 Ability to pass in saveAs menu, if pSelectSaveAs is list of menuItems
- # KTA 7/13/93 Added undefined task reference gReplaceExisitng
- # KTA 7/19/93 Changed call to FindWindow() to pass a descriptor.
- # KTA 7/22/93 if can't match (gActualFileName) reassign to string we typed
- # KTA 8/24/93 TCS stack parity check
- # KTA 9/14/93 gCustomRetrievedDoc wasn't being used because it was not
- # defined as global
- # KTA 9/22/93 Changed gSaveOtherFormat to gSaveAsHook1
- # Changed gEndTimer to gSaveAsHook2
- # Changed gDismissSFPut to gSaveAsHook3
- # KTA 9/30/93 Updated the output after saving a document.
- # KTA 4/28/94 If couldn't match 'Replace Existing' Try again (slow Machine)
- # KTA 5/09/94 If not IsStandardFile() try to match again
- # ML 11/29/94 Added exception handling support
- # ML 12/13/94 revised IsSys7 to gIsSys7
- # KTA 2/14/95 Added BooleanFlag to FindWindow() call
- # KTA 2/14/95 Call _MatchBoolean before trying to collect buttons on
- # 'Replace Existing' Dialog to avoid calling the DefaultHandler.
- # KTA 2/28/95 Handle filenames longer than 31 characters
- # KTA 2/28/95 Added call to TruncateString().
- # ML 11/20/95 revise for dirty quit - add pCheckSaveDocWindow
- #########################################################################
- TASK SaveAs(pNameDoc := "", pReplaceFlag := true, pSelectSaveAs := False,
- pPathlist := global gSFPUTLocation, pCheckSaveDocWindow := 1)
- begin
- global gIsSys7, gLastSavedFile, gActualFileName;
- returnVal := 0;
-
- if(isUndefined(global gIsSys7))
- isSystem7();
-
- if (pSelectSaveAs)
- begin
- TCSStart({ 1, global kTCSetSFSave },"SaveAs"); # Start TCS
- if(typeOf(pSelectSaveAs) = 'list')
- thisReturn := selectmenuItem(pSelectSaveAs[1],pSelectSaveAs[2]);
- else
- thisReturn := selectmenuItem("Save As", "File");
- TCSEnd({ 1, global kTCSetSFSave },thisReturn); # Select the MenuItem
- end;
-
- wait(2);
- ## Check to see if Standard File is present
- isPresent := IsStandardFile();
- if not(isPresent)
- begin
- wait(8);
- isPresent := IsStandardFile();
- end;
-
- ## Continue only if Standard File is present
- if (isPresent)
- begin
- SFPutDesc:= _match ([window o:1],1); # Save off the descriptor
-
- LogStr("############## Standard File - Save ##############");
- if (pNameDoc = "")
- pNameDoc := GetNewFileName(); #To get a name
-
- pNameDoc := TruncateString(pNameDoc, 31);
-
- if (pPathlist) and (gIsSys7) # No navigating in 6.0
- SFNavigate( pPathlist ,1);
-
- if (global gSaveAsHook1) # app specific hook
- call (gSaveAsHook1); # Useful for saving in other formats
-
- TypeStr(pNameDoc); # Type the name of the Document
- SpecialKey(ReturnKey, 'Return Key'); # Accept the SF dialog
-
- wait(3);
- if (global gReplaceExisting)
- Call(gReplaceExisting,pReplaceFlag,pNameDoc);
- else
- begin
- ## 7.0 and 6.0 have different 'Replace Existing' dialogs
- ## Determine if Replace Existing Dialog is present
- if(_MatchBoolean([button w:[window o:1]]))
- begin
- ReplaceExisting := _collect([button w:[window o:1]]);
- if (Card(ReplaceExisting) = 2)
- begin
- pNameDoc := ReplaceExist(pReplaceFlag, pNameDoc);
- returnval:= 2;
- end;
- end;
- else
- begin
- wait(5); # If couldn't match Replace Existing Try try again
- if(_MatchBoolean([button w:[window o:1]]))
- begin
- ReplaceExisting := _collect([button w:[window o:1]]);
- if (Card(ReplaceExisting) = 2)
- begin
- pNameDoc := ReplaceExist(pReplaceFlag, pNameDoc);
- returnval:= 2;
- end;
- else
- DialogCheck("",1); # Look for other problems
- end;
- end;
- end;
-
- if (global gSaveAsHook2) # app specific hook
- Call (gSaveAsHook2); # This can be useful in performance testing
-
- if not FindWindow(SFPutDesc, true) # if we can't find SFPut Dialog, indicates saved document for 1st time
- begin
- if not (returnval) # if not already reset from replace exist
- begin
- returnVal := 1; # set to success - no replace exist done
- TCSStart({ 2, global kTCSetSFSave },"Save a new file");
- TCSEnd({ 2, global kTCSetSFSave },1,,,pNameDoc);
- end; # if not returnval
- end;
-
- if (global gSaveAsHook3) # app specific
- call (gSaveAsHook3); # hook for handling anything
-
- if (returnval)
- begin
- gLastSavedFile := pNameDoc;
- theFile := '';
- if (pCheckSaveDocWindow)
- begin
- if (global gCustomRetrievedDoc)
- theFile := FindWindow(gCustomRetrievedDoc);
- else
- theFile := FindWindow(0);
- end;
- gActualFileName := theFile.t;
- if(gActualFileName)
- str := "The document's window is named - '{gActualFileName}'";
- else
- begin
- gActualFileName := pNameDoc;
- str := "The document is named - '{gActualFileName}'";
- end;
- LogStr(str);
- end;
- else
- logstr('Unable to dismiss the SFPut Dialog');
-
- end; # if (IsStandardFile())
-
- return(returnVal);
- end; # SaveAs()
-
- #########################################################################
- # OpenFile(pNameDoc,pSelectOpen, pPathList, pPartialPath)
- #========================================================================
- # Author: KTA
- # Description: This routine will select 'Open' from the 'File' menu, type
- # the string held in the pNameDoc parameter, and
- # then press the returnkey. It will check to see that
- # the frontmost window's title contains pNameDoc. If not,
- # it assumes that the wrong file opened. It will not select
- # 'Open' if the pSelectOpen parameter is false.
- # Parameters: pNameDoc - string name of document to open
- # pSelectOpen - 0 to disable selecting of the 'Open' menu item.
- # 1 to select 'Open' from the 'File' menu
- # 2 keyEq - 'o'
- # list - list containing ordinality of 'Open' menuItem.
- # pPathList - list defining path if file named <pNameDoc> not in
- # the current directory
- # pPartialPath := Whether to start navigation at the current dir or
- # at the desktop
- # 1 - start at current directory
- # 0 - start at desktop (not partial)
- # Returns: 1 - Document opened OK
- # 0 - Document not opened OK
- # Assumptions: Works with SF_Get, but don't have pNameDoc be to long
- # of a string.
- # Examples: OpenFile('Untit'); will select a document such as 'Untitled'.
- #========================================================================
- # History:
- # RTV 1/7/94 OpenFile was passing a list to TCSEnd instead of a string for the doc name
- # KTA 7/06/93 Performance support: OpenFileHook, EndTimer and
- # modified gCustomRetrievedDoc check
- # KTA 7/07/93 Ability to pass in open menu, if pSelectOpen is list of menuItems
- # Added global Actualfile so that we can do a better check to see if
- # the right file was opened. (intl)
- # KTA 7/22/93 added isSubString(pNameDoc,DocName) better filename verification
- # KTA 7/29/93 Changed check for StandardFile being Present
- # KTA 8/24/93 TCS stack parity check
- # KTA 9/9/93 Removed the slang 'BuckWheat' from the output line.
- # KTA 9/22/93 Changed gOpenFileHook to gOpenFileHook1
- # Changed gEndTimer to gOpenFileHook2
- # Removed gTimedEvent
- # ML 4/20/94 Handle Mac Easy Open Dialog
- # ML 5/2/94 Better check for MacEasy Open dialog
- # ML 5/3/94 Better check for MacEasy Open dialog
- # ML 11/29/94 Added exception handling support
- # KTA 2/14/95 Added BooleanFlag to FindWindow() call
- # MDF 04/29/96 Removed feature for Mac Easy Open Dialog (bug #1333521).
- #########################################################################
- TASK OpenFile(pNameDoc := "", pSelectOpen := 1, pPathList :={}, pPartialPath := 0)
- begin
- global gIsSys7, gActualFileName;
- returnVal := 0;
- failStr := "";
-
- if(isUndefined(global gIsSys7))
- isSystem7();
-
- if(pNameDoc)
- begin
- TCSStart({ 1, global kTCSetOpenDoc },"OpenFile"); # Start TCS
-
- if (pSelectOpen)
- begin
- if (Typeof(pSelectOpen) = 'list')
- selectmenuItem(pSelectOpen[1], pSelectOpen[2]); # Select the Open menuItem for intl
- else if (pSelectOpen = 1)
- selectmenuItem("Open", "File"); # Select the Open menuItem
- else if (pSelectOpen = 2)
- KeyEq('o'); # Keyboard equivelant 'o' for open
- end;
- wait(2);
- SFDialog := IsStandardFile();
- if (SFDialog)
- begin
- LogStr( "############## Standard File - Open ##############");
- if ( pPathList ) and (global gIsSys7) # No navigating in 6.0
- SFNavigate(pPathList,,,pPartialPath);
-
- if(global gOpenFileHook1)
- call (gOpenFileHook1); # Hook to do whatever required prior to typing filename
-
- TypeStr(pNameDoc); # Type the name of the file to open
-
- SpecialKey(ReturnKey, 'Return Key'); # Accept the dialog
-
- if(global gOpenFileHook2)
- Call(gOpenFileHook2); # Hook can be used for Performance
- Wait(3);
-
- #### Check to make sure Standard file is no longer present
- if (FindWindow(SFDialog, true)) # Call but don't log that it's not there
- begin
- failStr := "!@#$% Standard File is still present and it shouldn't be";
- LogStr(failStr);
- KeyEq('.'); # Exit (changed from 'cancel' button - intl)
- end;
- else if (global gCustomRetrievedDoc)
- begin
- customDoc := _match (gCustomRetrievedDoc,1);
- if(customDoc)
- begin
- DocName := customDoc.t;
- LogStr("The front window is named '{DocName}'");
- returnVal := 1; # return success
- end;
- else begin
- failStr := "!@#$% It appears that the wrong file was opened - {DocName}";
- LogStr(failStr);
- end;
- end; # else if global gCustomRetrievedDoc
- else # else do default doc checking
- begin
- ### match the top document window (Hopefully the Document that was just opened)
- theDoc := findWindow(0); # Match the document window
- DocName := theDoc.t;
- if not(DocName)
- LogStr("!@#$% No open window with grow and zoom boxes");
- else
- LogStr("The front document is named '{DocName}'");
-
- ## Is the document the one we expected
- if (isSubString(DocName,gActualFileName) or isSubString(pNameDoc,DocName)) # looks like the right file
- returnVal := 1; # return success
- else
- begin
- failStr := "!@#$% It appears that the wrong file was opened - {DocName}";
- LogStr(failStr);
- end;
- end; # else do default doc checking
- end; # if (IsStandardFile())
- TCSEnd({ 1, global kTCSetOpenDoc },returnVal,failStr,, DocName );
- end;
- else
- LogStr("!@#$% No file name was specified");
-
- return(returnVal);
- end; # OpenFile()
-
- #########################################################################
- # SFNavigate(pPathList, pTEToggle, pFinalReturn, pPartialPath)
- #========================================================================
- # Author: KTA
- # Description: Controls the navigation in Standard File.
- # Assigns a global gSFOriginalPath to the current directory
- # for return navigation.
- # Passes all parameters to SFType which performs actual navigation.
- # Parameters: pPathList := List of directories beginning with the disk name.
- # if pathlist := {} navigation will go to the Desktop.
- # otherwise it should be in the form {'hd', 'folder'};
- # pTEToggle := Whether toggling from a text edit field is required
- # to navigate.
- # 1 - Toggle
- # 0 - No toggling required
- # pPartialPath := Whether to start navigation at the current dir or
- # at the desktop
- # 1 - start at current directory
- # 0 - start at desktop
- # pFinalReturn := Whether to accept the final item in <pPathList>
- # Returns: PathList
- # Also sets global gSFOriginalPath to the original path
- #========================================================================
- # History:
- # KTA 7/18/94 Added a check to insure that PathList is defined.
- # ML 11/29/94 Added exception handling support
- # KTA 1/9/95 Fixed bug when StandardFile was already at the Desktop errors occured
- #########################################################################
- TASK SFNavigate( pPathList :={},pTEToggle :=0, pFinalReturn := 1, pPartialPath := 0)
- begin
- # Verify that Standard File is present
- if (IsStandardFile())
- begin
- NavigationRequired := 1;
- OrigPathList :={}; # Initialize variable
- try
- match[popup i:?Popupitems]; # match SF popup
- catch theError
- ExceptionDispatcher(theError);
- for x := 1 to (card PopUpItems-1) # Build a Pathlist
- OrigPathList := insert(PopUpItems[x].t,1,OrigPathList);
-
- if (OrigPathList = pPathList) # Is the current directory the desired directory
- begin
- NavigationRequired := 0;
- LogStr("The current directory is the desired directory - no navigation required");
- end;
- else if (TypeOf(pPathList) = "integer") # return to where you started
- begin
- if (pPathList = 1)
- pPathList := Global gSFOriginalPath;
- end;
-
- gSFOriginalPath := OrigPathList;
-
- if(NavigationRequired)
- begin
- SFPath := '';
- if(pPathList)
- begin
- for each item in pPathList # For logging purposes - build pathlist
- SFPath := SFPath + Item + ":";
- end;
- else
- SFPath := 'DeskTop:';
- LogStr( "Standard File Navigation to the path - ∂[{SFPath}∂]",3);
-
- SFType(pPathList,pTEToggle, pFinalReturn, pPartialPath);
- end;
- Return(pPathList);
- end;
- else
- return(0);
- end; # SFNavigate()
-
-
- #########################################################################
- # SFType(pPathList, pTEToggle, pFinalReturn, pPartialPath)
- #========================================================================
- # Author: KTA
- # Description: Performs navigation in Standard File.
- # If <pPartialPath> evaluates to false, Selects the 'DeskTop' button.
- # Then types each item in <pPathList> followed by a returnKey.
- # Parameters: pPathList := List of directories beginning with the disk name.
- # pTEToggle := Whether toggling from a text edit field is required
- # to navigate.
- # 1 - Toggle
- # 0 - No toggling required
- # pPartialPath := Whether to start navigation at the current dir or
- # at the desktop
- # 1 - start at current dir
- # 0 - start at desktop
- # pFinalReturn := Whether to accept the final item in <pPathList>
- # Returns: Nada
- #========================================================================
- # History:
- # ML 11/29/94 Added exception handling support
- # KTA 1/9/95 Fixed bug when StandardFile was already at the Desktop errors occured
- #########################################################################
- TASK SFType(pPathList,pTEToggle :=0, pFinalReturn := 1, pPartialPath := 0)
- begin
- if not (pPartialPath)
- begin
- if(_MatchBoolean([button t:'Desktop' e:True]))
- SelectButton('Desktop');
- end;
- if(pPathList)
- begin
- if (pTEToggle)
- _type ({TabKey}); # Makes directory list active
- wait(2);
- TypeList(pPathList,1,pFinalReturn); # Actual navigation
- if (pTEToggle)
- _type ({TabKey}); # Makes text edit active
- end;
- end; # SFType()
-
- #########################################################################
- # ReplaceExist( pReplaceFlag,pNameDoc)
- #========================================================================
- # Author: KTA
- # Description: Handles the 'Replace existing?' dialog.
- # Parameters: pReplaceFlag - Whether to Replace a document with the same name
- # or generate a unique name.
- # 1 - Overwrite document with same name.
- # 0 - Do not overwrite. Generate unique name.
- # pNameDoc := Name of file which already exists on disk.
- # Returns: pNameDoc ( will be identical to the initial one if pReplaceFlag is set)
- #========================================================================
- # History:
- # KTA 8/24/93 TCS stack parity check
- # ML 4/07/94 Added gReplaceExistHook1, gReplaceExistHook2
- # modal dialog blocks external tool calls
- # ML 11/29/94 Added exception handling support
- # KTA 2/28/95 Handle filenames longer than 31 characters
- # KTA 2/28/95 Added call to TruncateString().
- #########################################################################
- TASK ReplaceExist( pReplaceFlag := true, pNameDoc :='')
- begin
- global gIsSys7, gReplaceExistHook1, gReplaceExistHook2;
- LogStr(" -- Replace Existing?? --");
-
- if (gReplaceExistHook1)
- call (gReplaceExistHook1);
-
- # Different button names on dialog
- myButton := _collect([button w:[window o:1]]);
- firstButton := MyButton[1];
- secondButton := MyButton[2];
- if (firstButton.r[1] < secondButton.r[1])
- begin
- CancelString := firstButton.t;
- ReplaceString := secondButton.t;
- end;
- else
- begin
- ReplaceString := firstButton.t;
- CancelString := secondButton.t;
- end;
-
- if (pReplaceFlag) # Want to replace
- begin
- TCSStart({ 4, global kTCSetSFSave },"ReplaceExisting"); # Start TCS
- if(SelectButton(ReplaceString))
- returnVal := 1;
- else
- returnVal := 0;
- TCSEnd({ 4, global kTCSetSFSave }, returnVal);
- end;
- else
- begin # Don't want to replace
- TCSStart({ 3, global kTCSetSFSave },"CancelNewName"); # Start TCS
- if(SelectButton(CancelString))
- returnVal := 1;
- else
- returnVal := 0;
-
- TimeString := GetNewFileName(pNameDoc);
- if(global gIsSys7) # 7.0 and 6.0 handle text entry differently in SF
- _type ({rightArrowKey}); # Places I beam after existing text in SF text edit
-
- numChars := Card(pNameDoc);
- if (numChars >= 25) # Make sure we can add 7 char timestamp to make the file unique
- begin
- numAdditional := card(TimeString);
- numTimes := numAdditional - (31 - numChars);
- SpecialKey(deleteKey, 'DeleteKey', numTimes);
- tempStr := '';
-
- pNameDoc := TruncateString(pNameDoc, 31 - numAdditional);
- end;
- pNameDoc := "{pNameDoc}{TimeString}";
-
- TypeStr("{TimeString}"); # append time to pNameDoc in 6.0/7.0
- SpecialKey(returnKey, 'Return key');
- TCSEnd({ 3, global kTCSetSFSave },returnVal,,pNameDoc);
- end;
-
- if (gReplaceExistHook2)
- call (gReplaceExistHook2);
-
- return(pNameDoc);
- end; # ReplaceExist()
-
- #########################################################################
- # GetNewFileName(pFileName, pIncludeNameFlag)
- #========================================================================
- # Author: SL
- # Description: Gets a new file name by concatenating the app name and
- # the current time.
- # Parameters: pFileName - If this parameter is present, this routine will
- # only pass back the time. If this parameter is not
- # present, then this routine will pass back a string
- # consisting of the application name with the time
- # appended to it.
- # pIncludeNameFlag - if true will append time and Sec to end of
- # name and return it.
- # Returns: newFileName - string name for new file name
- # or just a time and Sec string
- #========================================================================
- # History:
- # ML 11/29/94 Added exception handling support
- # ML 12/13/94 Removed global IsSys7
- #########################################################################
- TASK GetNewFileName(pFileName :="",pIncludeNameFlag := 0)
- begin
- match [time h:?Tm s:?Sc];
- if (pFileName)
- begin
- if(pIncludeNameFlag)
- newFileName := "{pFileName} {Tm}{Sc}";
- else
- newFileName := " {Tm}{Sc}";
- end;
- else
- begin
- try match [Application t:?appName];
- catch theError
- ExceptionDispatcher(theError);
- newFileName := "@!@{appName}-{Tm}{Sc}";
- end;
- return(newFileName);
- end; # GetNewFileName()
-
- #########################################################################
- # SFSelectPopupMenuItem(pPopupMenuItem)
- #========================================================================
- # Author: KTA
- # Description: Selects the popup menu item <pPopupMenuItem> from the Standard
- # File dialog.
- # Parameters: pPopupMenuItem - The ordinality or Title of the menuitem (where
- # the Displayed menuItem is ord 1 if using Ordinality).
- # Returns: nothing
- # Examples: SelectPopupMenuItem("Font");
- # SelectPopupMenuItem(2);
- # Assumptions: The popup menu is in window ord 1
- #========================================================================
- # History:
- # ML 11/29/94 Added exception handling support
- #########################################################################
- TASK SFSelectPopupMenuItem( pPopupMenuItem := '')
- begin
- if (IsStandardFile())
- begin
- try PopupMenu := match[popup R:?ThePopUpRect i:?PopupMenuItems];
- catch theError
- ExceptionDispatcher(theError);
- if (pPopupMenuItem = 0)
- return(1);
- x := ((ThePopUpRect[1]+ThePopUpRect[3])/2);
- y := ((ThePopUpRect[2]+ThePopUpRect[4])/2);
-
- if not(TypeOf(pPopupMenuItem) = 'integer')
- begin
- try Match[MenuItem t:/{pPopupMenuItem}≈/ o:?PopUpOrd m:[Popup]];
- catch theError
- ExceptionDispatcher(theError);
- pPopupMenuItem := PopUpOrd;
- end;
-
- ### do our own logging
- temp := global gDisableAllLogging;
- global gDisableAllLogging := 1;
- ### Now select menuitem
- MoveMouse(x,y);
- _pressMouse();
- wait(1);
- _move ('r',{ 0,16 * (pPopupMenuItem - 1) });
- wait(1);
- _releaseMouse();
-
- ### restore logging
- global gDisableAllLogging := temp;
- thePopupName := PopupMenuItems[pPopupMenuItem].t;
-
- ### log what just happened
- LogStr("Selected popup menu item ∂'{thePopupName}∂' from the Standard File popUp");
- Return(thePopupName);
- end;
- else
- return(0);
- end;
-
- #########################################################################
- # ModifyDocument()
- #========================================================================
- # Author: KTA
- # Description: This task is called to modify a document so a revert to saved can
- # be performed. If a global tqask reference (gModifyDocument) is
- # defined, it will be called. Otherwise the default of typing a
- # string will be used.
- # Parameters: none
- # Returns: 0 - failure
- # 1 - success
- # Examples: ModifyDocument()
- # Assumptions:
- #========================================================================
- # History:
- # KTA 7/30/93 Added returnVal and return
- # KTA 9/28/93 isUndefined(returnVal)
- # KTA 9/28/93 Added TCS - 'Modify a Document'
- # KTA 10/05/93 Change returnVal to a 1 if it was successful
- # KTA 12/14/93 gModifyDoc can return a -1 and test was unsuccessful
- #########################################################################
- TASK ModifyDocument()
- begin
- TCReturnVal := 0;
- ErrStr := "";
- TCSStart({ 1, global kTCSetRevertDoc }, "Modify a Document");
- if (global gModifyDocument)
- begin
- TCReturnVal := call (gModifyDocument);
- if(isUndefined(TCReturnVal)) # If the gModifyDocument hook doesn't return a value
- begin
- ErrStr := "Failed because there was no return value";
- TCReturnVal := 0; # no value returned from hook - have to fail.
- end;
-
- if(TCReturnVal < 1) # if gModifyDoc was successFul
- returnVal := 0; # return a failure
- else
- returnVal := 1; # return a success
- end;
- else
- begin
- TypeStr("If 'Revert' worked, this shouldn't be here!");
- TCReturnVal := 1; #Hopefully this works to modify the document
- returnVal := 1; # return a success
- end;
- TCSEnd({ 1, global kTCSetRevertDoc }, TCReturnVal, ErrStr);
- return(returnVal);
- end;
-
- #########################################################################
- # Revert(pRevertMI)
- #========================================================================
- # Author: KTA
- # Description: If RevertMI is defined as the menuItem for revert it will be selected.
- # Otherwise a menuItem with the word 'Revert' in it will be selected.
- # A dialog will normally appear confirming the revert request.
- # Several methods will be used when attempting to dismiss the dialog.
- # Attempts to matck buttons "OK", "Yes", "Revert", are made, then
- # typing the returnKey. If RevertMi is defined then DialogCheck()
- # Will be called to output the static text in the dialog and the type
- # the returnKey.
- # Parameters: pRevertMI - List containing the ordinality of the revert menuItem.
- # Returns: nada
- # Examples: Revert()
- # Assumptions:
- #========================================================================
- # History:
- # KTA 7/12/93 Pass in pRevertMI for intl
- # KTA 8/24/93 TCS stack parity check
- # KTA 10/15/93 Added longer wait before trying to dismiss dialog and
- # support for hierachical menus
- # ML 11/29/94 Added exception handling support
- # ML 11/29/94 Revise for correct logging if not "Revert" menuitem
- # Added return value
- # ML 11/20/95 add support for gRevertString, gOKString, gYesString (int'l)
- # MDF 04/26/96 Fixed bug in Intl case where revert button wouldn't get
- # selected if it wasn't the default.
- #########################################################################
- TASK Revert(pRevertMI := '')
- begin
- global gApptitle, gRevertString, gOKString, gYesString;
- returnVal := 0;
- failStr := '';
-
- if (IsUndefined (gRevertString))
- revertString := "Revert";
- else
- revertString := gRevertString;
- if (IsUndefined (gOKString))
- okString := "OK";
- else
- okString := gOKString;
- if (IsUndefined (gYesString))
- yesString := "Yes";
- else
- yesString := gYesString;
-
- TCSStart({ 2, global kTCSetRevertDoc },"Revert"); # Start TCS
- if (pRevertMI = '')
- begin
- if (_matchBoolean (
- [menu t:'File' i:{ [menuItem t:/Revert≈(≈∂n≈)*/ e:true o:?ord] } ]))
- begin
- try begin
- match [menu t:'File' i:{ [menuItem t:/Revert≈(≈∂n≈)*/ e:true o:?ord] } ]!;
- match [menu t:'File' i:{ [menuItem t:?item e:true o:ord] } ]!;
- SelectMenuItem(item,'File');
- if (_matchBoolean ([button t:okString]))
- SelectButton('OK');
- else if (_matchBoolean ([button t:yesString]))
- SelectButton('Yes');
- else if (_matchBoolean ([button t:revertString]))
- SelectButton('Revert');
- else # try default if no 'yes' or 'OK' button
- SpecialKey(returnKey, 'Return key');
- DialogReturn := DialogCheck("",1);
- if(DialogReturn)
- failStr := DialogReturn;
- else
- returnVal := 1;
- end; # try
- catch theError
- ExceptionDispatcher(theError);
- end; # if _matchBoolean
- else
- failStr := "There is no enabled menu item titled 'Revert' in {gApptitle}";
- end; # if (pRevertMI = '')
- Else if(TypeOf(pRevertMI) = 'list') # Pass in Ord for (Intl)
- begin
- if (Card(pRevertMI) = 2)
- returnVal := SelectMenuItem(pRevertMI[1], pRevertMI[2]);
- else if (Card(pRevertMI) = 3)
- returnVal := SelectMenuItem(pRevertMI[1], pRevertMI[2], pRevertMI[3]);
- Wait(2);
- if (_matchBoolean ([button t:okString]))
- SelectButton(okString);
- else if (_matchBoolean ([button t:yesString]))
- SelectButton(yesString);
- else if (_matchBoolean ([button t:revertString]))
- SelectButton(revertString);
- else # try default button
- SpecialKey(returnKey, 'Return key');
- DialogCheck("",1);
- end;
- if failStr
- logstr(failStr);
- TCSEnd( { 2, global kTCSetRevertDoc }, returnVal, failStr);
- return(returnVal);
- end;
-
- #########################################################################
- # IsStandardFile(pLogIt)
- #========================================================================
- # Author: KTA
- # Description: Checks to see if the Standard File dialog is present
- # Parameters: pLogIt - Flag indicating whether or not to output
- # the nonexistence of the StandardFile dialog.
- # Returns: 1 - if the Standard File dialog is present
- # 0 - if the Standard File dialog is not present
- # Examples: IsStandardFile()
- # Assumptions:
- #========================================================================
- # History:
- # KTA 7/7/93 Added enhanced check for StandardFile for intl systems
- # KTA 7/29/93 If StandardFile return a window descriptor of front window
- # ML 11/29/94 Added exception handling support
- # ML 2/6/95 Use MatchBoolean instead of Match
- # Check before collecting button and useritem
- # KTA 2/28/95 Insure descriptors are for the front window
- #########################################################################
- TASK IsStandardFile(pLogIt := 1)
- begin
- returnVal := 0;
- if (_matchBoolean([button t:"Desktop" w:[window o:1]]!))
- returnVal := _match([window o:1]!,1);
- else
- begin
- if (_matchBoolean([button w:[window o:1]]))
- NumButtons := _collect([button w:[window o:1]]);
- if (_matchBoolean([useritem w:[window o:1]]))
- NumUserItem := _collect([useritem w:[window o:1]]);
- if((Card(NumButtons) >= 4) and (Card(NumUserItem) >= 1))
- returnVal := _match([window o:1]!,1);
- end;
- if not(returnVal) and (pLogIt)
- LogStr( "The Standard_File dialog is not present");
-
- return(returnVal);
- end;
-
- #########################################################################
- # CancelStandardFile(pHowCancel, pSaveAsMenu)
- #========================================================================
- # Author: KTA
- # Description: Selects Save As and Cancels it
- # Parameters: pHowCancel - method to cancel
- # 0 := KeyEq('.');
- # 1 := selectButton('Cancel');
- # 2 := SpecialKey(escapeKey,"Escape key");
- # pSaveAsMenu - list containing the ordinality of 'Save As' menu item.
- # - anything else will cause the hardcoded string 'Save As'
- # to be use in matching the menuItem.
- # Returns: 1 - if cancelling occured as expected
- # 0 - if it didn't
- # Examples: CancelStandardFile()
- # Assumptions:
- #========================================================================
- # History:
- # KTA 7/8/93 Added pHowCancel method 2 := escapekey
- # KTA 7/8/93 Added pSaveAsMenu the SaveAs menu descriptor
- # KTA 8/24/93 TCS stack parity check
- # ML 11/29/94 Added exception handling support
- # ML 2/6/95 Use MatchBoolean instead of Match
- #########################################################################
- TASK CancelStandardFile(pHowCancel := 0, pSaveAsMenu := 0)
- begin
- failStr := "";
- returnVal := 0;
-
- if(pHowCancel = 1)
- TCSNum := 5;
- else
- TCSNum := 6;
-
- TCSStart({ TCSNum, global kTCSetSFSave },"SaveAs/Cancel"); # Start TCS
- if (TypeOf(pSaveAsMenu) = 'list')
- SelectMenuItem(pSaveAsMenu[1],pSaveAsMenu[2]); ## Save/Cancel
- else
- SelectMenuItem("Save As",'File'); ## Save/Cancel
- wait(3);
- if(IsStandardFile()) # Check to see if standard file is present
- begin
- if(pHowCancel = 0)
- KeyEq('.');
- else if(pHowCancel = 1)
- begin
- if (_matchBoolean([button t:'Cancel']))
- selectButton('Cancel'); # Cancel the Standard SF_Put Dialog
- else
- begin
- SpecialKey(escapeKey,"Escape key"); # Help insure success - (intl)
- failStr := "No 'Cancel' button found - Hit the escape key instead.";
- end;
- end;
- else if(pHowCancel = 2)
- SpecialKey(escapeKey,"Escape key");
-
- if not(IsStandardFile(0)) # Check to see if standard file is not present
- returnVal := 1;
- else
- failStr := "Standard_File is still present and shouldn't be";
- end;
- TCSEnd({ TCSNum, global kTCSetSFSave }, returnVal,failStr);
- return(returnVal);
- end;
-
- #########################################################################
- # Save(pSaveMethod)
- #========================================================================
- # Author: KTA
- # Description: Selects Save - calls Save As if Standard File appears
- # Parameters: pSaveMethod - Method to save
- # 1 := Save from File Menu
- # 2 := Command-'s'
- # Returns: Nothing
- # Examples: Save()
- # Assumptions:
- #========================================================================
- # History:
- # KTA 7/8/93 Added pSaveMethod input parameter & pSaveMethod(2)
- # KTA 8/24/93 TCS stack parity check
- # ML 11/29/94 Added exception handling support
- #########################################################################
- TASK Save(pSaveMethod := 1)
- begin
- if(pSaveMethod = 1)
- begin
- if (_matchBoolean ([menuItem t:'Save' m:[menu t:'File' e:true] e:true]!))
- begin
- TCSStart({ 7, global kTCSetSFSave },"Save using Save menu item"); # Start TCS
- TCSEnd({ 7, global kTCSetSFSave }, SelectMenuItem("Save",'File'));
- if(isStandardFile(0)) # if StandardFile is present
- begin
- SaveAs(); # Call SF handler
- end;
- end;
- else
- pSaveMethod := 2; # Help insure success (intl)
- end;
- if(pSaveMethod = 2)
- keyEq('s');
- end;